package com.parachutes.aspbillcore.controller;

import com.parachutes.aspbillapi.domain.BusOrder;
import com.parachutes.aspbillapi.domain.Result;

import com.parachutes.aspbillapi.service.BusOrderService;
import com.parachutes.aspbillapi.util.OrderNumberGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    BusOrderService orderService;

    @PostMapping
    public Result createOrder(@RequestBody BusOrder order) {
        order.setOutTradeNo(OrderNumberGenerator.generateOrderNumber());
        if (!"withdraw".equals(order.getType())){
            order.setSubject("API分享平台钱包充值");
        }else {
            order.setSubject("API分享平台收益提现");
        }
        order.setStatus("0");
        orderService.save(order);
        return Result.of(true, "success", order.getOutTradeNo());
    }
}
